<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">samples/cpp/tutorial_code/features2D/Homography/decompose_homography.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>An example program with homography decomposition.</p>
<p>Check <a class="el" href="../../d9/dab/tutorial_homography.html">the corresponding tutorial</a> for more details.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d0/d9c/core_2include_2opencv2_2core_8hpp.html">opencv2/core.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d4/dd5/highgui_8hpp.html">opencv2/highgui.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="../../d2/d28/calib3d_8hpp.html">opencv2/calib3d.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d8/dcc/namespacestd.html">std</a>;</div><div class="line"><span class="keyword">using namespace </span><a class="code" href="../../d2/d75/namespacecv.html">cv</a>;</div><div class="line"></div><div class="line"><span class="keyword">namespace</span></div><div class="line">{</div><div class="line"><span class="keyword">enum</span> Pattern { CHESSBOARD, CIRCLES_GRID, ASYMMETRIC_CIRCLES_GRID };</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> calcChessboardCorners(<a name="_a0"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> boardSize, <span class="keywordtype">float</span> squareSize, vector&lt;Point3f&gt;&amp; corners, Pattern patternType = CHESSBOARD)</div><div class="line">{</div><div class="line">    corners.resize(0);</div><div class="line"></div><div class="line">    <span class="keywordflow">switch</span> (patternType) {</div><div class="line">    <span class="keywordflow">case</span> CHESSBOARD:</div><div class="line">    <span class="keywordflow">case</span> CIRCLES_GRID:</div><div class="line">        <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; boardSize.<a name="a1"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>; i++ )</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> j = 0; j &lt; boardSize.<a name="a2"></a><a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>; j++ )</div><div class="line">                corners.push_back(<a name="_a3"></a><a class="code" href="../../df/d6c/classcv_1_1Point3__.html">Point3f</a>(<span class="keywordtype">float</span>(j*squareSize),</div><div class="line">                                          <span class="keywordtype">float</span>(i*squareSize), 0));</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">    <span class="keywordflow">case</span> ASYMMETRIC_CIRCLES_GRID:</div><div class="line">        <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; boardSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#a1d289dce6b5d8006a54f3ee0259fc545">height</a>; i++ )</div><div class="line">            <span class="keywordflow">for</span>( <span class="keywordtype">int</span> j = 0; j &lt; boardSize.<a class="code" href="../../d6/d50/classcv_1_1Size__.html#abfe0367b32c407ddccf5ddf92667c73d">width</a>; j++ )</div><div class="line">                corners.push_back(<a class="code" href="../../df/d6c/classcv_1_1Point3__.html">Point3f</a>(<span class="keywordtype">float</span>((2*j + i % 2)*squareSize),</div><div class="line">                                          <span class="keywordtype">float</span>(i*squareSize), 0));</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line"></div><div class="line">    <span class="keywordflow">default</span>:</div><div class="line">        <a name="a4"></a><a class="code" href="../../db/de0/group__core__utils.html#ga5b48c333c777666e076bd7052799f891">CV_Error</a>(<a name="a5"></a><a class="code" href="../../d1/d0d/namespacecv_1_1Error.html#a759fa1af92f7aa7377c76ffb142abccaaf587497af64537041ee62c04a92b755d">Error::StsBadArg</a>, <span class="stringliteral">&quot;Unknown pattern type\n&quot;</span>);</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><a name="_a6"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> computeHomography(<span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;R_1to2, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;tvec_1to2, <span class="keyword">const</span> <span class="keywordtype">double</span> d_inv, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;normal)</div><div class="line">{</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> homography = R_1to2 + d_inv * tvec_1to2*normal.<a name="a7"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>();</div><div class="line">    <span class="keywordflow">return</span> homography;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> computeC2MC1(<span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;R1, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;tvec1, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;R2, <span class="keyword">const</span> <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;tvec2,</div><div class="line">                  <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;R_1to2, <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> &amp;tvec_1to2)</div><div class="line">{</div><div class="line">    <span class="comment">//c2Mc1 = c2Mo * oMc1 = c2Mo * c1Mo.inv()</span></div><div class="line">    R_1to2 = R2 * R1.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>();</div><div class="line">    tvec_1to2 = R2 * (-R1.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>()*tvec1) + tvec2;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">void</span> decomposeHomography(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;img1Path, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;img2Path, <span class="keyword">const</span> <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> &amp;patternSize,</div><div class="line">                         <span class="keyword">const</span> <span class="keywordtype">float</span> squareSize, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;intrinsicsPath)</div><div class="line">{</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> img1 = <a name="a8"></a><a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a name="a9"></a><a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>( img1Path) );</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> img2 = <a class="code" href="../../d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56">imread</a>( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>( img2Path) );</div><div class="line"></div><div class="line">    vector&lt;Point2f&gt; corners1, corners2;</div><div class="line">    <span class="keywordtype">bool</span> found1 = <a name="a10"></a><a class="code" href="../../d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a">findChessboardCorners</a>(img1, patternSize, corners1);</div><div class="line">    <span class="keywordtype">bool</span> found2 = <a class="code" href="../../d9/d0c/group__calib3d.html#ga93efa9b0aa890de240ca32b11253dd4a">findChessboardCorners</a>(img2, patternSize, corners2);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (!found1 || !found2)</div><div class="line">    {</div><div class="line">        cout &lt;&lt; <span class="stringliteral">&quot;Error, cannot find the chessboard corners in both images.&quot;</span> &lt;&lt; endl;</div><div class="line">        <span class="keywordflow">return</span>;</div><div class="line">    }</div><div class="line"></div><div class="line">    vector&lt;Point3f&gt; objectPoints;</div><div class="line">    calcChessboardCorners(patternSize, squareSize, objectPoints);</div><div class="line"></div><div class="line">    <a name="_a11"></a><a class="code" href="../../da/d56/classcv_1_1FileStorage.html">FileStorage</a> fs( <a class="code" href="../../d6/dba/group__core__utils__samples.html#ga3a33b00033b46c698ff6340d95569c13">samples::findFile</a>( intrinsicsPath ), FileStorage::READ);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> cameraMatrix, distCoeffs;</div><div class="line">    fs[<span class="stringliteral">&quot;camera_matrix&quot;</span>] &gt;&gt; cameraMatrix;</div><div class="line">    fs[<span class="stringliteral">&quot;distortion_coefficients&quot;</span>] &gt;&gt; distCoeffs;</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> rvec1, tvec1;</div><div class="line">    <a name="a12"></a><a class="code" href="../../d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d">solvePnP</a>(objectPoints, corners1, cameraMatrix, distCoeffs, rvec1, tvec1);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> rvec2, tvec2;</div><div class="line">    <a class="code" href="../../d9/d0c/group__calib3d.html#ga549c2075fac14829ff4a58bc931c033d">solvePnP</a>(objectPoints, corners2, cameraMatrix, distCoeffs, rvec2, tvec2);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> R1, R2;</div><div class="line">    <a name="a13"></a><a class="code" href="../../d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac">Rodrigues</a>(rvec1, R1);</div><div class="line">    <a class="code" href="../../d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac">Rodrigues</a>(rvec2, R2);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> R_1to2, t_1to2;</div><div class="line">    computeC2MC1(R1, tvec1, R2, tvec2, R_1to2, t_1to2);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> rvec_1to2;</div><div class="line">    <a class="code" href="../../d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac">Rodrigues</a>(R_1to2, rvec_1to2);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> normal = (<a name="_a14"></a><a class="code" href="../../df/dfc/classcv_1_1Mat__.html">Mat_&lt;double&gt;</a>(3,1) &lt;&lt; 0, 0, 1);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> normal1 = R1*normal;</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> origin(3, 1, <a name="a15"></a><a class="code" href="../../d1/d1b/group__core__hal__interface.html#ga30a562691cc5987bc88eb7bb7a8faf2b">CV_64F</a>, <a name="a16"></a><a class="code" href="../../dc/d84/group__core__basic.html#ga599fe92e910c027be274233eccad7beb">Scalar</a>(0));</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> origin1 = R1*origin + tvec1;</div><div class="line">    <span class="keywordtype">double</span> d_inv1 = 1.0 / normal1.<a name="a17"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a0f683eab191eeece33dfc64ae299a9cb">dot</a>(origin1);</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> homography_euclidean = computeHomography(R_1to2, t_1to2, d_inv1, normal1);</div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> homography = cameraMatrix * homography_euclidean * cameraMatrix.<a name="a18"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#a039eb3c6740a850696a12519a4b8bfc6">inv</a>();</div><div class="line"></div><div class="line">    homography /= homography.<a name="a19"></a><a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">double</span>&gt;(2,2);</div><div class="line">    homography_euclidean /= homography_euclidean.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aa5d20fc86d41d59e4d71ae93daee9726">at</a>&lt;<span class="keywordtype">double</span>&gt;(2,2);</div><div class="line"></div><div class="line">    vector&lt;Mat&gt; Rs_decomp, ts_decomp, normals_decomp;</div><div class="line">    <span class="keywordtype">int</span> solutions = <a name="a20"></a><a class="code" href="../../d9/d0c/group__calib3d.html#ga7f60bdff78833d1e3fd6d9d0fd538d92">decomposeHomographyMat</a>(homography, cameraMatrix, Rs_decomp, ts_decomp, normals_decomp);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Decompose homography matrix computed from the camera displacement:&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; solutions; i++)</div><div class="line">    {</div><div class="line">      <span class="keywordtype">double</span> factor_d1 = 1.0 / d_inv1;</div><div class="line">      <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> rvec_decomp;</div><div class="line">      <a class="code" href="../../d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac">Rodrigues</a>(Rs_decomp[i], rvec_decomp);</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;Solution &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;:&quot;</span> &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;rvec from homography decomposition: &quot;</span> &lt;&lt; rvec_decomp.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;rvec from camera displacement: &quot;</span> &lt;&lt; rvec_1to2.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;tvec from homography decomposition: &quot;</span> &lt;&lt; ts_decomp[i].<a name="a21"></a><a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; <span class="stringliteral">&quot; and scaled by d: &quot;</span> &lt;&lt; factor_d1 * ts_decomp[i].<a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;tvec from camera displacement: &quot;</span> &lt;&lt; t_1to2.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;plane normal from homography decomposition: &quot;</span> &lt;&lt; normals_decomp[i].<a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;plane normal at camera 1 pose: &quot;</span> &lt;&lt; normal1.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    }</div><div class="line"></div><div class="line">    <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> H = <a name="a22"></a><a class="code" href="../../d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780">findHomography</a>(corners1, corners2);</div><div class="line"></div><div class="line">    solutions = <a class="code" href="../../d9/d0c/group__calib3d.html#ga7f60bdff78833d1e3fd6d9d0fd538d92">decomposeHomographyMat</a>(H, cameraMatrix, Rs_decomp, ts_decomp, normals_decomp);</div><div class="line">    cout &lt;&lt; <span class="stringliteral">&quot;Decompose homography matrix estimated by findHomography():&quot;</span> &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; solutions; i++)</div><div class="line">    {</div><div class="line">      <span class="keywordtype">double</span> factor_d1 = 1.0 / d_inv1;</div><div class="line">      <a class="code" href="../../d3/d63/classcv_1_1Mat.html">Mat</a> rvec_decomp;</div><div class="line">      <a class="code" href="../../d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac">Rodrigues</a>(Rs_decomp[i], rvec_decomp);</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;Solution &quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;:&quot;</span> &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;rvec from homography decomposition: &quot;</span> &lt;&lt; rvec_decomp.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;rvec from camera displacement: &quot;</span> &lt;&lt; rvec_1to2.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;tvec from homography decomposition: &quot;</span> &lt;&lt; ts_decomp[i].<a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; <span class="stringliteral">&quot; and scaled by d: &quot;</span> &lt;&lt; factor_d1 * ts_decomp[i].<a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;tvec from camera displacement: &quot;</span> &lt;&lt; t_1to2.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;plane normal from homography decomposition: &quot;</span> &lt;&lt; normals_decomp[i].<a class="code" href="../../d1/d10/classcv_1_1MatExpr.html#af69e70f213b05e51527b80f8e5f2d08f">t</a>() &lt;&lt; endl;</div><div class="line">      cout &lt;&lt; <span class="stringliteral">&quot;plane normal at camera 1 pose: &quot;</span> &lt;&lt; normal1.<a class="code" href="../../d3/d63/classcv_1_1Mat.html#aaa428c60ccb6d8ea5de18f63dfac8e11">t</a>() &lt;&lt; endl &lt;&lt; endl;</div><div class="line">    }</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span>* <a name="a23"></a><a class="code" href="../../d1/dae/namespacecv_1_1gapi_1_1ie.html#a3ab1729bcaf2d08e30dd2bc645410908">params</a></div><div class="line">    = <span class="stringliteral">&quot;{ help h         |       | print usage }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ image1         | left02.jpg | path to the source chessboard image }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ image2         | left01.jpg | path to the desired chessboard image }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ intrinsics     | left_intrinsics.yml | path to camera intrinsics }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ width bw       | 9     | chessboard width }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ height bh      | 6     | chessboard height }&quot;</span></div><div class="line">      <span class="stringliteral">&quot;{ square_size    | 0.025 | chessboard square size }&quot;</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div><div class="line">{</div><div class="line">    <a name="_a24"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html">CommandLineParser</a> parser(argc, argv, <a class="code" href="../../d1/dae/namespacecv_1_1gapi_1_1ie.html#a3ab1729bcaf2d08e30dd2bc645410908">params</a>);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ( parser.<a name="a25"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a8c41cf242b2ad8c0472e3b57893ef200">has</a>(<span class="stringliteral">&quot;help&quot;</span>) )</div><div class="line">    {</div><div class="line">        parser.<a name="a26"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a2e11e779047efded23f75d9c5c5dd82e">about</a>( <span class="stringliteral">&quot;Code for homography tutorial.\n&quot;</span></div><div class="line">                      <span class="stringliteral">&quot;Example 4: decompose the homography matrix.\n&quot;</span> );</div><div class="line">        parser.<a name="a27"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a84cda3794b765332bfe43bf8367222fb">printMessage</a>();</div><div class="line">        <span class="keywordflow">return</span> 0;</div><div class="line">    }</div><div class="line"></div><div class="line">    <a class="code" href="../../d6/d50/classcv_1_1Size__.html">Size</a> patternSize(parser.<a name="a28"></a><a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;width&quot;</span>), parser.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">int</span>&gt;(<span class="stringliteral">&quot;height&quot;</span>));</div><div class="line">    <span class="keywordtype">float</span> squareSize = (float) parser.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<span class="keywordtype">double</span>&gt;(<span class="stringliteral">&quot;square_size&quot;</span>);</div><div class="line">    decomposeHomography(parser.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(<span class="stringliteral">&quot;image1&quot;</span>),</div><div class="line">                        parser.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(<span class="stringliteral">&quot;image2&quot;</span>),</div><div class="line">                        patternSize, squareSize,</div><div class="line">                        parser.<a class="code" href="../../d0/d2e/classcv_1_1CommandLineParser.html#a190215863579a6d244dccfd261ee0224">get</a>&lt;<a class="code" href="../../dc/d84/group__core__basic.html#ga1f6634802eeadfd7245bc75cf3e216c2">String</a>&gt;(<span class="stringliteral">&quot;intrinsics&quot;</span>));</div><div class="line"></div><div class="line">    <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:29 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
